package com.example.yuhuaqiu.testviewpager;

import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;

import com.example.yuhuaqiu.util.MyPagerAdapter;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private ViewPager viewPager;
    private List<View> allViews;
    private MyPagerAdapter pagerAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        viewPager = (ViewPager) findViewById(R.id.viewPager);
        View firstView = LayoutInflater.from(this).inflate(R.layout.first,null);
        View secondView = LayoutInflater.from(this).inflate(R.layout.second,null);
        View thirdView = LayoutInflater.from(this).inflate(R.layout.third,null);
        allViews = new ArrayList<>();
        allViews.add(firstView);
        allViews.add(secondView);
        allViews.add(thirdView);
        viewPager.setOffscreenPageLimit(3);
        pagerAdapter = new MyPagerAdapter(allViews);
        viewPager.setAdapter(pagerAdapter);
    }
}
